package org.example.springmybatisdemo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.XSlf4j;
import org.example.springmybatisdemo.entity.Emp;
import org.example.springmybatisdemo.entity.EmpLoginInfo;
import org.example.springmybatisdemo.entity.Result;
import org.example.springmybatisdemo.service.EmpService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "登录")
@RestController
public class LoginController {
    private final EmpService empService;

    public LoginController(EmpService empService) {
        this.empService = empService;
    }

    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public Result<EmpLoginInfo> login(@RequestBody Emp emp) {
        System.out.println("登录");
        EmpLoginInfo loginInfo = empService.login(emp);
        if(loginInfo == null) {
            return Result.fail("用户名或密码错误", 400);
        }
        return Result.success(loginInfo);
    }
}
